function Banner(){
    this.index = 0;
    this.lis = $(".banner-ul li").length;

}
Banner.prototype.loop=function() {
    var self = this
    self.timer = setInterval(function() {
        if(self.index >= self.lis - 1){
            self.index = 0;
        }else {
            self.index++;
        }
        $(".banner-ul").animate({
            left: -798*self.index
        },)
        $('.page-control li').eq(self.index).addClass('active').siblings('li').removeClass('active');
    }, 2000);
}

Banner.prototype.listen=function() {
    var self = this
    $("#banner-group").hover(function() {
            $(".arrow").show();
            clearInterval(self.timer);
        },
        function() {
            $(".arrow").hide();
            self.loop();
        }
    )
}

Banner.prototype.arrow=function() {
    var self = this;
    $(".left-arrow").click(function() {
        if(self.index === 0) {
            self.index = self.lis - 1;
        }else {
            self.index--;
        }
        $(".banner-ul").stop().animate({
            left: -798*self.index
        },)
        $('.page-control li').eq(self.index).addClass('active').siblings('li').removeClass('active');
    })
    $(".right-arrow").click(function() {
        if(self.index === self.lis - 1) {
            self.index = 0;
        }else {
            self.index++;
        }
        $(".banner-ul").stop().animate({
            left: -798*self.index
        },)
        $('.page-control li').eq(self.index).addClass('active').siblings('li').removeClass('active');
    })

}

Banner.prototype.init_page = function (){
    var self = this
    var page_ul = $('.page-control');
    for (var i = 0; i < self.lis; i++){
        var li = $("<li></li>")
        page_ul.append(li);
        if(i === 0) {
            li.addClass("active");
        }
    }
}

Banner.prototype.init_width = function (){
    var self = this;
    $('.banner-ul').css('width', self.lis * 798);
}

Banner.prototype.init_control = function (){
    var self = this;
    var circles = $('.page-control li');
    circles.each(function(index1, ele){
        $(ele).click(function() {
            self.index = index1;
            $(".banner-ul").animate({
            left: -798*self.index
            },)
            $(ele).addClass('active').siblings('li').removeClass('active');
        })
    })

}

Banner.prototype.moreNews = function () {
    var btn = $('.load-more')
    btn.click(function (){
        window.location.href = window.location.href + "news/news_list/";
    })
}
Banner.prototype.run=function() {
    this.listen();
    this.init_width();
    this.loop();
    this.arrow();
    this.init_page();
    this.init_control();
    this.moreNews();
}

$(function() {
    var banner = new Banner();
    banner.run();
})